package com.adinnet.admin.system.controller;

import com.adinnet.admin.common.service.CommonService;
import com.adinnet.admin.operation.model.vo.OperationResp;
import com.adinnet.admin.operation.service.OperationService;
import com.adinnet.admin.school.service.SchoolService;
import com.adinnet.admin.system.model.LoginRecord;
import com.adinnet.admin.system.model.vo.SysUserInfo;
import com.adinnet.admin.system.service.LoginRecordService;
import com.adinnet.core.PageResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 登录日志管理
 **/
@Controller
@RequestMapping("/sys/loginRecord")
public class LoginRecordController {
    @Autowired
    private LoginRecordService loginRecordService;

    @Autowired
    private OperationService operationService;
    @Autowired
    private CommonService commonService;
    @Autowired
    private SchoolService schoolService;

    @RequiresPermissions("loginRecord:view")
    @RequestMapping()
    public String loginRecord(Model model) {
        SysUserInfo sysUserInfo=commonService.getLoginUser();
        model.addAttribute("schools", schoolService.getListByUserRole(sysUserInfo));
        return "system/loginRecord.html";
    }

    /**
     * 查询所有登录日志 t_login_record
     **/
    @ResponseBody
    @RequestMapping("/list")
    public PageResult<LoginRecord> list(Integer page, Integer limit, String startDate, String endDate, String account) {
        return loginRecordService.listFull(page, limit, startDate, endDate, account);
    }

    /**
     * @description  查询所有登录日志 t_operation
     * @author lkp
     * @param
     * @param: page
     * @param: limit
     * @param: startDate
     * @param: endDate
     * @param: account
     * @createTime 2020/12/15 16:47
     */
    @ResponseBody
    @RequestMapping("/opList")
    public PageResult<OperationResp> opList(Integer page, Integer limit, String startDate, String endDate,String userName, Integer schoolId) {
        return operationService.listFull(page, limit, startDate, endDate, userName,schoolId);
    }


}
